import router from '@system.router';
import sensor from '@system.sensor';
import {jsCallJavaAbility} from "../../common/JsCallJavaAbilityUtils.js"

export default {
    data: {
        audioText: "识别中。。。",
        question: "",
        before_heart: []
    },
    reset() {
        this.audioText = "没有人能够熄灭漫天星光";
    },
    goAnswer() {
        router.push({
            uri: "pages/answer/answer",
            params: {
                question: this.question
            }
        })
    },
    sendHeartData() {
        jsCallJavaAbility.callAbility("com.panda_coder.linedetector.watch.ConnectServiceAbility", 100, {
            "hearts": this.before_heart
        })
    },
    compareText(){
      if(this.audioText.indexOf("没有人能够熄灭漫天星光")>-1){
          this.goAnswer()
      }
    },
    onInit() {
        this.$watch('before_heart', 'sendHeartData');
        this.$watch('audioText','compareText')
    },
    onShow() {
        sensor.subscribeHeartRate({
            success: (ret) => {
                if (ret.heartRate < 200){
                    this.before_heart.push(ret.heartRate)
                }
            },
            fail: (data, code) => {
                console.log(code)
            }
        })
    },
    onDestroy() {
        sensor.unsubscribeHeartRate()
    }
}
